package com.linkoog.devtools.dubbo.linemarker.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.linkoog.devtools.dubbo.raw_index.DubboMethod;
import com.linkoog.devtools.dubbo.toolwindow.DubboToolWindowManager;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

import static com.intellij.openapi.actionSystem.CommonDataKeys.PROJECT;

public class DubboTestToolWinAction extends AnAction {

    private final DubboMethod dubboMethod;


    public DubboTestToolWinAction(@NotNull DubboMethod dubboMethod, @NotNull String text, String description, Icon icon){
        super(text, description, icon);
        this.dubboMethod = dubboMethod;
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        Project project = e.getData(PROJECT);
        if (project == null) return;

        DubboToolWindowManager.getInstance(project).show(dubboMethod);
    }

    @Override
    public void update(AnActionEvent e) {
        Project project = e.getData(PROJECT);
        e.getPresentation().setVisible(project != null);
    }

}
